package edu.gatech.cs2340.group7.wheresmystuffapp.junit;

import android.test.ActivityInstrumentationTestCase2;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import edu.gatech.cs2340.group7.wheresmystuffapp.R;
import edu.gatech.cs2340.group7.wheresmystuffapp.model.Account;
import edu.gatech.cs2340.group7.wheresmystuffapp.model.DatabaseHelper;
import edu.gatech.cs2340.group7.wheresmystuffapp.model.User;
import edu.gatech.cs2340.group7.wheresmystuffapp.views.UnlockAccountView;

/**
 * Tests unlocking an account
 * @author tbowling3
 * @version 1.0
 */
@SuppressWarnings("unused")
public class UnlockAccountViewTest extends ActivityInstrumentationTestCase2<UnlockAccountView> {	
	private EditText etAdminEmailUnlock;
	private Button bAdminUnlock;
	private UnlockAccountView activity;
	private TextView tvAdminUnlockResult;
	private DatabaseHelper myDbHelper;

	public void testUnlockAccount() {
		Account user1 = new User("user1","password1","1234567890");
		Account user2 = new User("user2","password2","1234567890");
		Account user3 = new User("user3","password3","1234567890");
		
		user1.setLocked(true);
		user2.setLocked(true);
		user3.setLocked(true);
		
		assertTrue(user1.isLocked());
		user1.setLocked(false);
		assertFalse(user1.isLocked());
		
		assertTrue(user2.isLocked());
		user2.setLocked(false);
		assertFalse(user2.isLocked());
		
		assertTrue(user3.isLocked());
		user3.setLocked(false);
		assertFalse(user3.isLocked());
		
//		myDbHelper.addAccount(user1);
//		myDbHelper.addAccount(user2);
//		myDbHelper.addAccount(user3);
		
//		activity.runOnUiThread(new Runnable() {
//
//			@Override
//			public void run() {
//				try {
//					etAdminEmailUnlock.setText("user1");
//					bAdminUnlock.callOnClick();
//					//assertEquals("Text result does not match expected", tvAdminUnlockResult.getText().toString(), "Account for user1 was already unlocked");
//					
//					etAdminEmailUnlock.setText("user2");
//					bAdminUnlock.callOnClick();
//					//assertEquals("Text result does not match expected", tvAdminUnlockResult.getText().toString(), "Account for user2 unlocked");
//					
//					etAdminEmailUnlock.setText("user3");
//					bAdminUnlock.callOnClick();
//					assertEquals("Text result does not match expected", tvAdminUnlockResult.getText().toString(), "Account for user3 was already unlocked");
//					
//				}
//				catch(NullPointerException e) {
//					e.printStackTrace();
//				} // close catch
//				
//			} // close run
//			
//		});
	} // close testUnlockAccount method
	
	
	
	public UnlockAccountViewTest(Class<UnlockAccountView> activityClass) {
		super(activityClass);
		// TODO Auto-generated constructor stub
	}
	
	public UnlockAccountViewTest() {
		super(UnlockAccountView.class);
	}
	
	protected void setUp() throws Exception {
		super.setUp();
		
		setActivityInitialTouchMode(false);
		activity = getActivity();
		
		etAdminEmailUnlock = (EditText) activity.findViewById(R.id.et_admin_email_unlock);
		bAdminUnlock = (Button) activity.findViewById(R.id.b_admin_unlock);
		tvAdminUnlockResult = (TextView) activity.findViewById(R.id.tv_admin_unlock_result);
		myDbHelper = new DatabaseHelper(activity);
	}
	
	protected void tearDown() throws Exception {
		super.tearDown();
	}
}
